package cl.minvu.catastro.manager;

import java.math.BigInteger;
import java.util.List;

import javax.persistence.EntityManager;

import org.apache.log4j.Logger;

import cl.minvu.catastro.model.Genero;
import cl.minvu.catastro.model.Persona;
import cl.minvu.catastro.model.Zona;

public class ZonaManager extends AbstractManager {
	
	private static final Logger logger = Logger.getLogger(ZonaManager.class);
	
	/**
	 * TODO clase de prueba
	 */
	public void test() {
		EntityManager em = super.getEntityManager();
		
		Persona persona = new Persona();
		persona.setRut(new BigInteger("1"));
		persona.setGenero(new Genero());
		persona.getGenero().setIdgenero(1);
		
		em.getTransaction().begin();
		em.persist(persona);
		logger.info(persona);
		em.getTransaction().commit();
		
		super.close(em);
	}
	
	public void load() {
		EntityManager em = super.getEntityManager();
		Zona zona = em.find(Zona.class, 1);
		logger.info("Zona[id: " + zona.getIdzona() + ", glosa: " + zona.getGlosa());
		super.close(em);
	}
	
	public void list() {
		EntityManager em = super.getEntityManager();
		@SuppressWarnings("unchecked")
		List<Zona> zonas = em.createNamedQuery("Zona.findAll").getResultList();
		
		for (Zona zona : zonas) {
			logger.info(zona);
		}
		super.close(em);
	}

}
